class Round:
    def __init__(self, r):
        self.rung = r
        self.refresh()
        
    def refresh(self):
        self.hand = []
        self.color = None
        self.moveNum = 0
        
    def addMove(self, player, move):
        if(self.moveNum >= 4):
            print "no more moves should have been added"
        else:
            self.hand.append((player, move))
            if(self.color == None):
                self.color = move.suite
            self.moveNum += 1
         
    def getRound(self):
        rnd = ""
        for move in self.hand:
            rnd += str(move[1]) + ";"
        rnd = rnd.rstrip(";")
        return rnd 
           
    def roundComplete(self):
        if(self.moveNum == 4):
            return True
        else:
            return False
        
    def checkHand(self):
        rungCards = []
        startCards = []
        winner = None
        
        for player, card in self.hand:
            if card.suite == self.rung:
                rungCards.append((player, card))
            
        if(len(rungCards) == 1):
            winner = rungCards[0]
        elif(len(rungCards) > 1):
            winner = rungCards[0]
            for card in rungCards:
                if(winner[1] < card[1]):
                    winner = card
        else:
            for player, card in self.hand:
                if card.suite == self.color:
                    startCards.append((player, card))
                
            if(len(startCards) == 1):
                winner = startCards[0]
            elif(len(startCards) > 1):
                winner = startCards[0]
                for card in startCards:
                    if(winner[1] < card[1]):
                        winner = card
        return winner
    
    